package com.SuanFa.mayukun;

import java.util.*;

public class aaa {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        sc.nextLine();
        Map<Integer, String> map = new HashMap<>();
        for (int i = 0; i < n; i++) {
            String nums = sc.nextLine();
            nums = nums.replace(" ","");
//            System.out.println(nums);
            int key = Integer.parseInt(nums.charAt(0)+"");
            String value = nums.substring(1,key+1);
            map.put(key,value);
        }
        for (int i = 1; i <= m; i++) {
            int count=0;
            int temp = 0;
            for (String valueArray : map.values()) {
//                System.out.println(valueArray); // 打印数组
                if (valueArray.contains(i+"")){
                    temp++;
                    for (int j = 0; j < valueArray.length(); j++) {
                        if (valueArray.charAt(j)==i+'0'){
                            count++;
                        }
                    }
                }
            }
            System.out.println(temp+" "+count);
        }
    }
}
